//
//  ViewController.m
//  GPUImagePicture
//
//  Created by Xwoder on 2017/1/16.
//  Copyright © 2017年 Xwoder. All rights reserved.
//

#import "ViewController.h"
#import "GPUImage.h"

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    // 原始图片
    UIImage *inputImage = [UIImage imageNamed:@"input.jpeg"];
    
    GPUImagePicture *stillImageSource = [[GPUImagePicture alloc] initWithImage:inputImage];
    
    // 滤镜
    GPUImageSepiaFilter *stillImageFilter = [[GPUImageSepiaFilter alloc] init];
    stillImageFilter.intensity = 1;
    [stillImageSource addTarget:stillImageFilter];
    
    // 如果通过一个滤镜手动捕获一张图片
    // 需要调用-useNextFrameForImageCapture方法以告诉滤镜：你需要在稍后捕获该图片
    [stillImageFilter useNextFrameForImageCapture];
    // 渲染图片
    [stillImageSource processImage];
    
    // 输出图片
    UIImage *image = [stillImageFilter imageFromCurrentFramebuffer];
    
    // 显示图片
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.bounds = CGRectMake(0, 0, 320, 480);
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    imageView.center = self.view.center;
    imageView.image = image;
    [self.view addSubview:imageView];
}

// 对于单个滤镜，也可以使用如下代码处理图片
- (void)processImage {
    // 原始图片
    UIImage *inputImage = [UIImage imageNamed:@"input.jpg"];
    
    // 滤镜
    GPUImageSepiaFilter *stillImageFilter = [[GPUImageSepiaFilter alloc] init];
    stillImageFilter.intensity = 1;
    
    // 输出图片
    UIImage *image = [stillImageFilter imageByFilteringImage:inputImage];
    
    // code...
}

@end
